package project3.datasets;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import project3.datasets.parsers.DataSetParser;

/**
 * Default {@link DataSet} implementation.
 * 
 * @author Vika
 * @author Antonio
 */
public class DefaultDataSet extends AbstractDataSet {
	
	/** List of instances (rows) */
	private List<Instance> instances;

	/**
	 * Constructs a new DefaultDataSet.
	 *  
	 * @param parser The dataset parser
	 */
	public DefaultDataSet(DataSetParser parser) {
		super(parser);
	}

	public int size() {
		return this.instances.size();
	}

	/**
	 * Returns the instance's iterator.
	 */
	public Iterator<Instance> iterator() {
		return this.instances.iterator();
	}

	/**
	 * Returns the attribute iterator.
	 */
	public Iterator<Attribute> attributeIterator() {
		return new Iterator<Attribute>() {

			private int idx=0;
			
			public boolean hasNext() {
				return idx < attributes.length;
			}

			public Attribute next() {
				return attributes[idx++];
			}

			public void remove() {
				throw new Error("not implemented yet.");
			}
			
		};
	}

	@Override
	protected void addInstance(Instance instance) {
		if (instances == null) {
			instances = new ArrayList<Instance>();
		}
		this.instances.add(instance);
	}

}
